Skip to content

Conversation

gabritto
Copy link
Member

Fixes #1568.

As per my comment on the issue, the problem happens because in LSP, if an editRange is present in the completion response (i.e. we set a default editRange to be used for all completion items), then an item's insertText is ignored. This is in line with the behavior when you specify textEdits in individual items: insertText is also ignored in that case.
Ignoring insertText meant the client would use the item's label, e.g. name?, instead of the insertText's name.

We may get rid of this problem in the future if instead of appending ? in the item's label directly, we use the item's labelDetails.
But I want to fix the bug right away, and (1) not all clients support labelDetails, and (2) I'd like to have snippet completions implemented before figuring out the right labelDetails behavior, because snippet completions also use labelDetails.

@Copilot Copilot AI review requested due to automatic review settings August 13, 2025 20:55
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a bug where completion items with insertText were not being properly applied when an editRange was set in the completion defaults. The issue occurred because LSP clients ignore insertText when editRange is present, causing items like optional properties to show their label (e.g., name?) instead of the intended insert text (e.g., name).

  • Modifies completion logic to convert insertText to textEdit when editRange is set
  • Updates affected test cases to expect textEdit instead of insertText
  • Removes one test case that's no longer relevant

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.

Show a summary per file
File Description
internal/ls/completions.go Adds logic to convert insertText to textEdit when editRange is present in item defaults
internal/ls/completions_test.go Removes test case for static class member completions
internal/fourslash/tests/manual/completionsWithDeprecatedTag4_test.go Updates test to expect textEdit instead of insertText for optional property completion
internal/fourslash/tests/manual/completionsSelfDeclaring1_test.go Updates test to expect textEdit instead of insertText for optional property completion
internal/fourslash/tests/manual/completionsAtIncompleteObjectLiteralProperty_test.go Updates test to expect textEdit instead of insertText for optional property completion
internal/fourslash/tests/completionFilterText1_test.go Updates multiple test cases to expect textEdit instead of insertText for private field completions
internal/fourslash/_scripts/manualTests.txt Adds three test files to manual test list

},
},
},
{
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test file will be deleted as part of the snapshopt PR, and we also have fourslash tests now, so I just deleted this test case instead of updating it.

@gabritto gabritto added this pull request to the merge queue Aug 13, 2025
Merged via the queue into main with commit 3205d2e Aug 13, 2025
22 checks passed
@gabritto gabritto deleted the gabritto/issue1568 branch August 13, 2025 21:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Output from selecting optional property from auto complete modal incorrectly includes ? in JS object

2 participants